package Dao;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import Entity.Selection;

import mapper.Selectionmapper;

public class selectiondao implements Selectionmapper{
	private  static Selectionmapper selectionmapper;
	private  static SqlSession session;

	public selectiondao() throws IOException {
	 	String resource ="mybatis-config.xml";
		InputStream inputstream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlsessionfactory = new SqlSessionFactoryBuilder().build(inputstream);
		 session = sqlsessionfactory.openSession();
        selectionmapper =  session.getMapper(Selectionmapper.class);
    }
	public void close(){
		this.session.close();
	}
	@Override
	public List<String> courseRelatedStudents(String cid) {
		List<String> selectList = this.selectionmapper.courseRelatedStudents(cid);
		return selectList;
	}

	@Override
	public boolean CreatSelection(Selection selection) {
		Boolean iuser = this.selectionmapper.CreatSelection(selection);
		if(iuser == true){
			session.commit();
		}else{
			session.rollback();
		}
	
		return iuser;
	}

	@Override
	public List<String> querySelection(String id) {
		
		List<String> selectList = this.selectionmapper.querySelection(id);

		return selectList;
	}
	@Override
	public void delSelection(String cid) {
		this.selectionmapper.delSelection(cid);
		
	}

	
	

}
